package com.eleadmin.order.controller;

import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.damon.utils.utils.CacheUtils;
import com.eleadmin.damon.utils.utils.Utils;
import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.order.entity.ContainOceanApply;
import com.eleadmin.order.entity.ContainerBill;
import com.eleadmin.order.param.ContainerBillParam;
import com.eleadmin.order.service.ContainerBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSON;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;


/**
 * 拖车运单
 *
 * @author : Doman
 * @version ：1.0
 * @date : 2023-01-13 11:14:35
 */

@Api(tags = "拖车运单")
@RestController
@RequestMapping("/api/nt/order/containerBill")
public class ContainerBillNtController extends BaseController {

    @Autowired
    private ContainerBillService containerBillService;


    @ApiOperation("根据id查询拖车运单")
    @GetMapping("/detail/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        id = CacheUtils.containerBillCacheOutEF.get(id);
        String[] item = id.split(",");
        if (item[0].equals("orderSingle")) {
            return containerBillService.getById(item[1]);
        } else {
            return JsonResult.error();
        }
    }

    @ApiOperation("转发单个运单,免登陆,一般不超过2天")
    @GetMapping("/sendWithCache")
    public JsonResult sendWithCache(String id) {
        if (Utils.isNotEmpty(id)) {
            String uuid = UUID.randomUUID().toString();
            CacheUtils.containerBillCacheOutEF.put(uuid, "orderSingle," + id);
            return JsonResult.ok().put("data", uuid);
        }
        return JsonResult.error();
    }

}
